<!-- Horizontal Form -->
<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">添加角色</h3>
    </div>
    <!-- /.box-header -->
    <!-- form start -->
    <form class="form-horizontal">
        <div class="box-body">
            <div class="form-group">
                <label for="titleId" class="col-sm-2 control-label">标题</label>

                <div class="col-sm-10 titleC">
                    <input type="text" class="form-control" name="titleName" id="titleId" placeholder="标题..">
                </div>
            </div>

            <div class="form-group">
                <label for="contentId" class="col-sm-2 control-label">描述</label>
                <div class="col-sm-10">
                    <textarea rows="10" cols="90" id="contentId" placeholder="请输入具体公告内容..."/>
                </div>
            </div>

        </div>
        <!-- /.box-body -->
        <div class="box-footer">
            <button type="button" class="btn btn-default btn-cancel">取消</button>
            <button type="button" class="btn btn-info pull-right btn-save">保存</button>
        </div>
        <!-- /.box-footer -->
    </form>
</div>
<script type="text/javascript" src="bower_components/ztree/jquery.ztree.all.min.js"></script>
<script type="text/javascript">

    $(function () {
        //异步加载菜单信息,初始化页面菜单
        //showBack();

        $(".box-footer")
            .on("click", ".btn-save", doSaveOrUpdate)
            .on("click", ".btn-cancel", doCancel);

    });




    function doCancel() {
        var url = "notice/notice_list";
        $("#mainContentId")
            .load(url, function () {
                $("#mainContentId").removeData();
            });
    }

    function doSaveOrUpdate() {
        //1.参数(表单数据)
        var params = doGetEditFormData();
        if (!params.title.trim()) {
            alert("标题不能为空!");
            return;
        }
        if (!params.content.trim()) {
            alert("内容不能为空!");
            return;
        }
        var data = $("#mainContentId").data("data");
        if (data) params.id = data.id;
        //2.url
        var insertUrl = "notice/doSaveNotice";
        var updateUrl = "notice/doUpdateNotice";
        var url = data ? updateUrl : insertUrl;
        //3.ajax request
        $.post(url, params, function (result) {
            if (result.state == 1) {
                alert(result.message);
                doCancel();
            } else {
                alert(result.message);
            }
        })
    }

    function doGetEditFormData() {
        //1.获取角色自身信息
        var params = {
            title: $("#titleId").val(),
            content: $("#contentId").val()
        }
        return params;
    }


</script>